package utils.global.constant;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
@AllArgsConstructor
public class RestfulJson<T> implements Serializable {

    private String msg;
    private Integer code;
    private T data;

    public static <T> RestfulJson<T> success(String msg, T data) {
        return new RestfulJson<>(msg, 1, data);
    }

    public static <T> RestfulJson<T> success(T data) {
        return new RestfulJson<>("SUCCESS", 1, data);
    }

    public static RestfulJson success() {
        return new RestfulJson<>("SUCCESS", 1, null);
    }

    public static <T> RestfulJson<T> error(String msg, T data) {
        return new RestfulJson<>(msg, -1, data);
    }

    public static <T> RestfulJson<T> error(T data) {
        return new RestfulJson<>("FAILURE", -1, data);
    }

    public static RestfulJson error() {
        return new RestfulJson<>("FAILURE", -1, null);
    }

    public static <T> RestfulJson<T> type(RestfulType restfulType, T data) {
        return new RestfulJson<>(restfulType.getDescription(), restfulType.getCode(), data);
    }

    public static RestfulJson type(RestfulType restfulType) {
        return new RestfulJson<>(restfulType.getDescription(), restfulType.getCode(), null);
    }
}
